<?php
/*
 * @description: ...
 * @copyright Copyright (c) 2012-2017 Marin V. , Tykva A. , Kozel R. , Sokolov D.
 * @version 1.0
 * @link http://lecturebox.ru
*/

class IndexController extends Model_Controller
{

    public function init()
    {
        /**
         * В parent::init() выполняется создание объекта Zend_Auth - $this->auth
         * и определение id текущего пользователя - $this->user_id
         */
        parent::init();
    }

    public function indexAction()
    {
        $page = (int) $this->getRequest()->getParam('page', 1);

        $work = new Model_Lecture();
        $this->view->pages = $work->getPaginatorRows($page, 5, 0, 0);

        if(count($this->view->pages))
        {
            foreach($this->view->pages as $item)
                break;
            //$this->view->title = 'LectureBox.ru';
            $session = new Zend_Session_Namespace('lectureBox.l10n');
            if ($session->locale) {
                    if($session->locale == 'ru_RU'){
                        $this->view->headTitle('Главная', 'PREPEND');
                        $this->view->headMeta()->appendName('description',
                            'Все лекции в одной коробке');
                    } else {
                        $this->view->headTitle('MainPage', 'PREPEND');
                        $this->view->headMeta()->appendName('description',
                            'All lectures in one box');
                    }
            }
        }
        $this->view->user_id = $this->user_id;
    }
    
    
    public function popularAction()
    {
        $page = (int) $this->getRequest()->getParam('page', 1);

        $work = new Model_Lecture();
        $this->view->pages = $work->getPaginatorPopRows($page, 5, 0, 0);

        if(count($this->view->pages))
        {
            foreach($this->view->pages as $item)
                break;
            //$this->view->title = 'LectureBox.ru';
             $session = new Zend_Session_Namespace('lectureBox.l10n');
            if ($session->locale) {
                    if($session->locale == 'ru_RU'){
                        $this->view->headTitle('Главная', 'PREPEND');
                        $this->view->headMeta()->appendName('description',
                            'Все лекции в одной коробке');
                    } else {
                        $this->view->headTitle('MainPage', 'PREPEND');
                        $this->view->headMeta()->appendName('description',
                            'All lectures in one box');
                    }
            }
        }
        $this->view->user_id = $this->user_id;
    }
    public function localeAction()
  { 
    // if supported locale, add to session
    if (Zend_Validate::is($this->getRequest()->getParam('locale'), 'InArray', array('haystack' => array('en_US', 'ru_RU')))) {
      $session = new Zend_Session_Namespace('lectureBox.l10n');
      $session->locale = $this->getRequest()->getParam('locale');    
    } 
        
    // redirect to requesting URL
    $url = $this->getRequest()->getServer('HTTP_REFERER');
    $this->_redirect($url);      
  }

}

